package org.example.ioc.pro4_ioc_factorybean;

import org.springframework.beans.factory.FactoryBean;

import java.util.Random;

public class FruitFactoryBean implements FactoryBean<Fruit> {
    public FruitFactoryBean() {
        System.out.println("FruitFactoryBean的构造器");
    }
    @Override
    public Fruit getObject() throws Exception {
        //去类路径下去找 是否存在 某种 Fruit接口的实现类
        Random r=new Random();
        int num=r.nextInt(2);
        if(num==0){
            return new Apple_A();
        }else if(num==1){
            return new Apple_B();
        }else {
            return null;
        }
    }

    @Override
    public Class<?> getObjectType() {
        return Fruit.class;
    }

}
